# include <stdio.h>
#define MAXL 10000

/**
 * 添加一个字符
 * @Author   smallcatx0
 * @DateTime 2017-03-30
 * @param    cta        [容器地址]
 * @param    c          [待添加的字符串]
 * @param    k          [栈顶]
 * @return              [成功/失败(1/0)]
 */
int addIn_c(char * cta,char c,int *k){
    if (*k<MAXL/2){
        cta[*k] = c;
        *k=*k+1;
        return 1;
    }
    else return 0;
}
/**
 * 判断栈顶元素是否为 c 是则删除
 * @Author   smallcatx0
 * @DateTime 2017-03-31
 * @param    cta        [容器地址]
 * @param    c          [待删元素]
 * @param    k          [栈顶]
 * @return              [成功删除：1]
 */
int delFrom_c(char * cta,char c,int* k){
    if (cta[*k-1] == c){
        *k=*k-1;
        return 1;
    }
    else return 0;
}

/**
 * 匹配一组字符串的括号是否配对
 * @Author   smallcatx0
 * @DateTime 2017-03-30
 * @param    chs        [字符串地址]
 * @return              [匹配结果(1/0)]
 */
int mate_kh(char * chs){
    int j,k;
    char ch;
    char cta[MAXL/2]; 
    k = 0;
    for (j = 0; '\0'!=chs[j] ; ++j){
        ch = chs[j];
        if (ch=='('||ch=='[')  
            if(!addIn_c(cta,ch,&k)) return 0;
        if (ch==')')
            if(!delFrom_c(cta,'(',&k)) return 0;
        if (ch==']')
            if(!delFrom_c(cta,'[',&k)) return 0;
    }
    if(k==0) return 1; 
    else     return 0;
}
int main()
{
    int i;
    char len;
    char sc[100][MAXL];
    // char sc[100][MAXL]={"[(])","(])","([[]()])","[[]]()(([]))"};len=4;
    scanf("%d",&len);
    for (i = 0; i < len; ++i)
        scanf("%s",sc[i]);
    for (i = 0; i < len; ++i)
        mate_kh(sc[i])?printf("Yes\n") : printf("No\n");
    return 0;
}